/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controle.controladores;

/**
 *
 * @author Taeko
 */
public class PID extends ControladorAbstrato{

    private proporcional p;
    private integrativo i;
    private derivativo d;
    private double saida = 0.0, integral = 0.0, erroanterior = 0.0;
    
    public PID(double Kp,double Ki,double Kd){
        super(Kp, Ki, Kd);
        
        p = new proporcional(Kp);
        i = new integrativo(Ki);
        d = new derivativo(Kd);
    }
    
    @Override
    public double valorControle(double entrada, double h) {
        p.setContantes(Kp, Ki, Kd);
        i.setContantes(Kp, Ki, Kd);
        d.setContantes(Kp, Ki, Kd);
        
        return  p.valorControle(entrada, h) + i.valorControle(entrada, h) + d.valorControle(entrada, h);
    }

    public double valorControle2(double nivelT1, double erro, double dt) {
        if((nivelT1>=3 && erro>0) || (nivelT1 <=3 && erro<0)){
            
        }else{
            integral = integral + (erro * dt);
        }
        
        saida = (p.Kp * erro) + (d.Kd * (erro - erroanterior) / dt) + (i.Ki * integral);
        
        return saida;
    }
    
}
